home *** CD-ROM | disk | FTP | other *** search
/ University of Pittsburgh…tware Toolkit - Fall 2002 / Toolkit.iso / mac / Macintosh 9.x / Connectivity / Kerberos for Mac 4.0 / Mac OS 9 SDK 4.0 / Kerberos / ClassicGlue / ComErrLib.glue.c next >
Encoding:
C/C++ Source or Header  |  2002-02-20  |  3.7 KB  |  133 lines  |  [TEXT/MPS ]

  1. /* Include prototypes for glue functions */
  2. #include <com_err.h>
  3.  
  4. /* Hardcode library fragment name here */
  5. #define kLibraryName "\pMIT Kerberos•ComErrLib"
  6. #include <CodeFragments.h>
  7. #include <Gestalt.h>
  8. #include <Errors.h>
  9.  
  10. // Private function prototypes
  11.  
  12. static OSErr Find_Symbol(
  13.     Ptr* pSymAddr,
  14.     Str255 pSymName,
  15.     ProcInfoType pProcInfo);
  16.  
  17. static pascal Boolean HaveCFM(void);
  18.  
  19. static pascal OSErr GetSystemArchitecture(OSType *archType);
  20.  
  21. /* This code is directly from Technote 1077 */
  22.  
  23. /*    changed Library name to be hardcoded at the top of the file
  24.     instead in the middle of the code */
  25.  
  26. // Private functions
  27.  
  28. static pascal OSErr GetSystemArchitecture(OSType *archType)
  29. {
  30.     static long sSysArchitecture = 0; // static so we only Gestalt once.
  31.     OSErr tOSErr = noErr;
  32.  
  33.     *archType = kAnyCFragArch;   // assume wild architecture
  34.  
  35.     // If we don't know the system architecture yet...
  36.     if (sSysArchitecture == 0)
  37.     // ...Ask Gestalt what kind of machine we are running on.
  38.     tOSErr = Gestalt(gestaltSysArchitecture, &sSysArchitecture);
  39.  
  40.     if (tOSErr == noErr) // if no errors
  41.     {
  42.         if (sSysArchitecture == gestalt68k)   // 68k?
  43.             *archType = kMotorola68KCFragArch;   
  44.         else if (sSysArchitecture == gestaltPowerPC) // PPC?
  45.             *archType = kPowerPCCFragArch;       
  46.         else
  47.             tOSErr = gestaltUnknownErr;  // who knows what might be next?
  48.     }
  49.     return tOSErr;
  50. }
  51.  
  52. static pascal Boolean HaveCFM(void)
  53. {
  54.     long response;
  55.     return ( (Gestalt (gestaltCFMAttr, &response) == noErr) &&
  56.                 (((response >> gestaltCFMPresent) & 1) != 0));
  57. }
  58.  
  59. static OSErr Find_Symbol(
  60.     Ptr* pSymAddr,
  61.     Str255 pSymName,
  62.     ProcInfoType pProcInfo)
  63. {
  64.     static CFragConnectionID sCID = 0;
  65.     static OSType sArchType = kAnyCFragArch;
  66.     static OSErr sOSErr = noErr;
  67.  
  68.     Str255 errMessage;
  69.     Ptr mainAddr;
  70.     CFragSymbolClass symClass;
  71.     ISAType tISAType;
  72.  
  73.     if (sArchType == kAnyCFragArch)  // if architecture is undefined...
  74.     {
  75.         sCID = 0;     // ...force (re)connect to library
  76.         sOSErr = GetSystemArchitecture(&sArchType); // determine architecture
  77.         if (sOSErr != noErr)
  78.         return sOSErr; // OOPS!
  79.     }
  80.     
  81.     if (!HaveCFM()) {
  82.         // If we don't have CFM68K, return a reasonable-looking error.
  83.         sOSErr = cfragLibConnErr;
  84.         return sOSErr;
  85.     }
  86.  
  87.     if (sArchType == kMotorola68KCFragArch) // ...for CFM68K
  88.         tISAType = kM68kISA | kCFM68kRTA;
  89.     else if (sArchType == kPowerPCCFragArch)  // ...for PPC CFM
  90.         tISAType = kPowerPCISA | kPowerPCRTA;
  91.     else
  92.         sOSErr = gestaltUnknownErr; // who knows what might be next?
  93.  
  94.     if (sCID == 0) // If we haven't connected to the library yet...
  95.     {
  96.         // NOTE: The library name is hard coded here.
  97.         // I try to isolate the glue code, one file per library.
  98.         // I have had developers pass in the Library name to allow
  99.         // plug-in type support. Additional code has to be added to
  100.         // each entry points glue routine to support multiple or
  101.         // switching connection IDs.
  102.         sOSErr = GetSharedLibrary(kLibraryName, sArchType, kLoadCFrag,
  103.         &sCID, &mainAddr, errMessage);
  104.         if (sOSErr != noErr)
  105.         return sOSErr; // OOPS!
  106.     }
  107.  
  108.     // If we haven't looked up this symbol yet...
  109.     if ((Ptr) *pSymAddr == (Ptr) kUnresolvedCFragSymbolAddress)    
  110.     {
  111.         // ...look it up now
  112.         sOSErr = FindSymbol(sCID,pSymName,pSymAddr,&symClass);
  113.         if (sOSErr != noErr) // in case of error...
  114.         // ...clear the procedure pointer
  115.         *(Ptr*) &pSymAddr = (Ptr) kUnresolvedCFragSymbolAddress;
  116. #    if !GENERATINGCFM // if this is classic 68k code...
  117.             *pSymAddr = (Ptr)NewRoutineDescriptorTrap((ProcPtr) *pSymAddr,
  118.             pProcInfo, tISAType);  // ...create a routine descriptor...
  119. #    endif
  120.     }
  121.     return sOSErr;
  122. }
  123.  
  124. /* --------------------------------- */
  125. /* Autogenerated section starts here */
  126. /* --------------------------------- */
  127. #include <ComErrLib.glue.h>
  128.  
  129. Boolean ComErrLibraryIsPresent ()
  130. {
  131.     Ptr    symAddr;
  132.     return (Find_Symbol (&symAddr, "\perror_message", error_message_ProcInfo)) == noErr;
  133. }